﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Slaks.Graphs.Analysis.ClusteringMeasures
{
    class AvgFMeasure : ClusteringMeasureBase
    {
        public override object evaluate(GraphList[] clusters, Slaks.Graphs.Category.CategoriesFile categoriesFile)
        {
            double measureSum = 0d;
            int totalCount = 0;
            foreach (GraphList cluster in clusters)
            {
                var clusterRecall = IRAnalysis.GetClusterRecall(cluster, categoriesFile);
                var clusterPrecision = IRAnalysis.GetClusterPrecision(cluster, categoriesFile);
                var fmeasure = (2 * clusterPrecision) / (clusterPrecision + clusterRecall);
                measureSum += fmeasure * cluster.Count;
                totalCount += cluster.Count;
            }
            return totalCount == 0 ? 0 : measureSum / totalCount;
        }
       
        public override string getMeasureName()
        {
            return "AvgFMeasure";
        }
    }
}
